// game resources
var g_resources = [{
    name: "territorio",
    type: "image",
    src: "images/territorio.png"
}, {
    name: "procida",
    type: "tmx",
    src: "data/ProcidaComplete.tmx"
}, {
    name: "mainCharacter",
    type: "image",
    src: "images/mainCharacter.png"}
	,{
    name: "secondlayer",
    type: "image",
    src: "images/secondlayer.png"}
    ,{
    name: "pittore",
    type: "image",
    src: "images/pittore.png"}
    ,{
    name: "portone",
    type: "image",
    src: "images/portone.png"}
    ,{
    name: "barca",
    type: "image",
    src: "images/barca.png"}
    ,{
    name: "grassangle3",
    type: "image",
    src: "images/grassangle3.png"}
    ,{
    name: "abbazia",
    type: "image",
    src: "images/abbazia.png"}
    ,{
    name: "bar",
    type: "image",
    src: "images/bar.png"}
    ,{
    name: "comune",
    type: "image",
    src: "images/comune.png"}
    ,{
    name: "congrega",
    type: "image",
    src: "images/congrega.png"}
    ,{
    name: "ferramenta",
    type: "image",
    src: "images/ferramenta.png"}
    ,{
    name: "fioraio",
    type: "image",
    src: "images/fioraio.png"}
    ,{
    name: "fruttivendolo",
    type: "image",
    src: "images/fruttivendolo.png"}
    ,{
    name: "lavoro",
    type: "image",
    src: "images/lavoro.png"}
    ,{
    name: "orto",
    type: "image",
    src: "images/orto.png"}
    ,{
    name: "palestra",
    type: "image",
    src: "images/palestra.png"}
    ,{
    name: "pescheria",
    type: "image",
    src: "images/pescheria.png"}
    ,{
    name: "professore",
    type: "image",
    src: "images/professore.png"}
    ,{
    name: "scultore",
    type: "image",
    src: "images/scultore.png"}
    ,{
    name: "tendone",
    type: "image",
    src: "images/tendone.png"}
    ,{
    name: "mostra",
    type: "image",
    src: "images/chiesa.png"}
    ,{
    name: "erba",
    type: "image",
    src: "images/grass.png"}
    
    ];

var begin = true;

var jsApp = {
    /* --- 
     Initialize the jsApp 
     --- */
    onload: function() {
 
        // init the video
        if (!me.video.init('jsapp', 680, 480, false, 1.0)) {
            alert("Sorry but your browser does not support html 5 canvas.");
            return;
        }
 
        // initialize the "audio"
        //me.audio.init("mp3,ogg");
 
        // set all resources to be loaded
        me.loader.onload = this.loaded.bind(this);
 
        // set all resources to be loaded
        me.loader.preload(g_resources);
 
        // load everything & display a loading screen
        me.state.change(me.state.LOADING);
    },
	// Whether a dialog box is waiting for input.
    "modal" : false,

    // `true` when an object's y-coordinate changes to put it at the proper Z-order.
    "wantsResort" : false, 
   /* ---
 
   callback when everything is loaded
     
   ---  */
     
loaded: function ()
{

	// set the "Play/Ingame" Screen Object
	me.state.set(me.state.PLAY, new PlayScreen());
	// add our player entity in the entity pool
	me.entityPool.add("mainPlayer", PlayerEntity);
	
	// add places where user can go
	me.entityPool.add("PittoreEntity", PostoEntity);
	me.entityPool.add("AbbaziaEntity", PostoEntity);
	me.entityPool.add("VivaraEntity", PostoEntity);
	me.entityPool.add("PortoneEntity", PostoEntity);
	me.entityPool.add("PescaEntity", PostoEntity);
	me.entityPool.add("BarEntity", PostoEntity);
	me.entityPool.add("ComuneEntity", PostoEntity);
	me.entityPool.add("CongregaEntity", PostoEntity);
	me.entityPool.add("FerramentaEntity", PostoEntity);
	me.entityPool.add("FioraioEntity", PostoEntity);
	me.entityPool.add("FruttivendoloEntity", PostoEntity);
	me.entityPool.add("LavoroEntity", PostoEntity);
	me.entityPool.add("OrtoEntity", PostoEntity);
	me.entityPool.add("PalestraEntity", PostoEntity);
	me.entityPool.add("PescheriaEntity", PostoEntity);
	me.entityPool.add("ProfessoreEntity", PostoEntity);
	me.entityPool.add("ScultoreEntity", PostoEntity);
	me.entityPool.add("TendoneEntity", PostoEntity);
	me.entityPool.add("MostraEntity", PostoEntity);
    me.sys.gravity = 0;         
	// enable the keyboard
    // Key bindings.
    me.input.bindKey(me.input.KEY.UP,       "up");
    me.input.bindKey(me.input.KEY.LEFT,     "left");
    me.input.bindKey(me.input.KEY.DOWN,     "down");
    me.input.bindKey(me.input.KEY.RIGHT,    "right");
    me.input.bindKey(me.input.KEY.W,        "up");
    me.input.bindKey(me.input.KEY.A,        "left");
    me.input.bindKey(me.input.KEY.S,        "down");
    me.input.bindKey(me.input.KEY.D,        "right");
    me.input.bindKey(me.input.KEY.ENTER,    "action", true);
    me.input.bindKey(me.input.KEY.SPACE,    "action", true);
    me.input.bindKey(me.input.KEY.SHIFT,    "shift");
    me.input.bindKey(me.input.KEY.Z,        "attack", true);
    me.input.bindKey(me.input.KEY.ESC,      "skip", true);
     
	// start the game 
	me.state.change(me.state.PLAY);
	messaggioTesto = document.getElementById("messaggio");
	messaggioTesto.innerHTML = "Per iniziare, muovi il tuo personaggio, che ora si trova fuori al pozzo con le frecce direzionali della tastiera. <br/>La tua missione consiste nel costruire un mistero in 24 giorni. Non c'è tempo da perdere! Per qualunque dubbio, clicca sul tasto 'Aiuto' che trovi in alto a destra. <br/> Buon lavoro!";
	titleAzione = document.getElementById("titleAzione");
	titleAzione.innerHTML =  "Benvenuto a Procida!";
	conferma.className = " button invisibile";


}
     
};
// jsApp
/* the in game stuff*/
var PlayScreen = me.ScreenObject.extend({
 
    onResetEvent: function() {
        // stuff to reset on state change
		 me.levelDirector.loadLevel("procida");
    },
 
    /* ---
 
     action to perform when game is finished (state change)
 
     --- */
    onDestroyEvent: function() {
    }
 
});
 
//bootstrap :)
window.onReady(function() {
    jsApp.onload();
});